package com.firefly.dao.assembler.cms;

import com.firefly.dao.dao.cms.po.TypePo;
import com.firefly.dao.dto.cms.TypeDto;
import com.firefly.dao.vo.cms.TypeTreeVo;
import com.firefly.dao.vo.cms.TypeVo;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @description: 分类类型转换
 * @author: lzg(萤火科技 ： 854378082 @ qq.com)
 * @date: 2022/12/13
 **/
@Component
public class TypeAssembler {
    public List<TypeTreeVo> getTreeList(List<TypePo> list) {
        List<TypeTreeVo> result = new ArrayList<>();
        list.forEach(item -> {
            TypeTreeVo tmp = new TypeTreeVo();
            tmp.setId(item.getId());
            tmp.setParentId(item.getParentId());
            tmp.setName(item.getName());
            tmp.setSort(item.getSort());
            result.add(tmp);
        });
        return result;
    }

    public TypePo getPo(TypeDto detail){
        TypePo entity = new TypePo();
        entity.setId(detail.getId());
        entity.setParentId(detail.getParentId());
        entity.setName(detail.getName());
        entity.setSort(detail.getSort());
        return entity;
    }

    public TypeVo getVo(TypePo entity){
        TypeVo detail = new TypeVo();
        detail.setId(entity.getId());
        detail.setParentId(entity.getParentId());
        detail.setName(entity.getName());
        detail.setSort(entity.getSort());
        return detail;
    }
}
